//
//  LSPlayTricksViewController.m
//  LookScore
//
//  Created by wws on 2018/5/3.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSPlayTricksViewController.h"
#import "LSPlayTricksCell.h"
#import "LSRefreshHeaderView.h"
#import "LSPlayTricksModel.h"
#import "LSHomeArticleDetailVController.h"
//#import "BattlefieldTableViewCell.h"
//#import "LSRightImageCell.h"
@interface LSPlayTricksViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *dataSource;
}
@property (nonatomic,strong)UITableView *tableView;
@property(assign,nonatomic)NSInteger  pageIndex;
@property(strong,nonatomic)NSMutableArray *dataSource;
@end

@implementation LSPlayTricksViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.alpha = 1 ;
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, LSScreenWidth, LSScreenHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor =LSBackGroundColor;
//        _tableView.backgroundColor =[UIColor redColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = @[].mutableCopy;
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
//    self.title = @"足球百科";
    [self.view addSubview:self.tableView];
//    [self loadData:YES];
    
    LSRefreshHeaderView *header = [LSRefreshHeaderView headerWithRefreshingBlock:^{
        [self loadData:YES];
    }];
    self.tableView.mj_header = header;// 设置header
    [header beginRefreshing];
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [self loadData:NO];
    }];
}
- (void)loadData:(BOOL)refresh{
    if (refresh) {
        
        self.pageIndex = 0;
    }else{
        
        self.pageIndex += 1;
    }
    NSDictionary *articlehotDic = @{@"pageIndex":@(self.pageIndex)};
    [LSHttpEnclosureTool GET:LSSKILLINFO parameters:articlehotDic resBlock:^(id responseObject) {
        MyLog(@"data --- %@",responseObject);
        if (responseObject) {
            if (refresh) {
                [self.dataSource removeAllObjects];
            }
            for (NSDictionary *dict in responseObject[@"ArticleQueryList"]) {
                LSPlayTricksModel *model=[LSPlayTricksModel mj_objectWithKeyValues:dict];
                [self.dataSource addObject:model];
            }
            
            
        }else{
            
            self.pageIndex -= 1;
            
        }
        [self endRefreshing];
        [self.tableView reloadData];
    }];
    
}

#pragma mark ------------ UITableViewDelegate,UITableViewDataSource --
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.row == 0) {
//        return 98;
//    }else if (indexPath.row == 1){
//        return 250;
//    }
    return 126;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    if (indexPath.row == 0 || indexPath.row == 1) {
//        LSPlayTricksCell *cell1 = [LSPlayTricksCell PlayTricksCellByTableView:tableView];
//        LSPlayTricksModel *model=[LSPlayTricksModel mj_objectWithKeyValues:self.dataSource[indexPath.row]];
//        cell1.model = model;
//        return cell1;
//
//    }else{
    LSTricksOneImageCell *cell = [LSTricksOneImageCell TricksOneImageCellByTableView:tableView];
//    LSPlayTricksModel *model=[LSPlayTricksModel mj_objectWithKeyValues:self.dataSource[indexPath.row]];
    cell.model = self.dataSource[indexPath.row];
    return cell;
//    };
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LSTricksOneImageCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    LSHomeArticleDetailVController *articleVC=[[LSHomeArticleDetailVController alloc]init];
    articleVC.articleId=cell.model.Id;
    [self.navigationController pushViewController:articleVC animated:YES];
}

//点击分享
- (void)click_share{
    
    
    
}

- (void)endRefreshing{
    if ([self.tableView.mj_header isRefreshing]) {
        [self.tableView.mj_header endRefreshing];
    }
    if ([self.tableView.mj_footer isRefreshing]) {
        [self.tableView.mj_footer endRefreshing];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end

